package com.example.demo.controller;


import com.example.demo.ResultEntity;
import com.example.demo.pojo.Fight;
import com.example.demo.service.CityService;
import com.example.demo.service.FightService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@CrossOrigin("http://localhost:8081")
@RestController
public class FightController {
    @Resource
    CityService service1;
    @Resource
    FightService service2;


    @GetMapping("/test01")
    public Map<String,Object> query(){
        Map<String,Object> map=new HashMap<>();
        map.put("s","aadwa");
        return map;
    }

    @GetMapping("/query/City")
    public Map<String,Object> queryCity(){
        Map<String,Object> map=new HashMap<>();
        map.put("city",service1.getSelectCity());
        return map;
    }

    @GetMapping("/query/Fights")
    public Map<String,Object> queryFight(@RequestParam(value = "deid",required = false,defaultValue = "0") Integer deid,
                                                            @RequestParam(value = "arid",required = false,defaultValue = "0")Integer arid,
                                                            @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
                                                            @RequestParam(value = "pageSize",required = false,defaultValue = "3")Integer pageSize){
        Map<String,Object> map=new HashMap<>();
        map.put("fight",service2.getSelectByFight(deid, arid, pageNum, pageSize));
        return map;
    }
    @PostMapping("/save/Fights")
    public ResultEntity<Integer> AddFights(@RequestBody Fight fight){
        return ResultEntity.successWithoutData(service2.getInsert(fight));
    }
}
